home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-22 | 3.8 KB | 90 lines | [TEXT/ttxt] |
- /*
- © 1991 Dick Guertin
- */
-
- This is a text file describing how to build an XCMD using THINK-C.
- Enclosed are several header.h files and source.c files that comprise
- a working example of the Dialog XCMD described in Chapter 3 of "XCMD's
- for HyperCard" by Gary Bond (MIS: Press; ISBN 0-943518-85-7). The 29
- "glue" routines are in the XCmdGlue.c file. The XCmdBlock is defined
- in the HyperXCmd.h file, along with prototypes for all the "glue" code.
-
- The XCmdUtil.h and XCmdUtil.c files contain the commonly used routines,
- both from the Dialog XCMD example, and the examples in Chapter 6.
- These include the following:
-
- short GetParamCount (XCmdBlockPtr, short min, short max);
- short CheckParamCount (XCmdBlockPtr, short amount);
- void Fail (XCmdBlockPtr, char*);
- Handle CopyStrToHand (char*);
- long HandleToNum (XCmdBlockPtr, Handle);
- void HandleToPstr (Str255, Handle);
- char* ToCstr (char*);
- char* ToPstr (char*);
-
- I've modified GetParamCount to take minimum, maximum; and CheckParamCount
- to take a required amount. They no longer take a "string" error msg.
- Instead, they return either the valid paramCount, or they return -1.
- The main program calls Fail with the appropriate error message. This
- makes the xxxParamCount routines independent of the main program.
-
- XCmdStrings.c contains many of the string-functions that normally come
- from the ANSII Library. But since the library is so large, I've written
- these string-functions here to reduce the size of the final XCMD code.
-
- In THINK-C, you would open the XCmdGlue.π project. Then you should
- use "Set Project Type" under the Project menu to setup the XCMD info.
- The enclosed example defines the following information:
-
- X Code Resource
- File Type: XCMD
- Creator: RlGq
- Name: Dialog
- Type: XCMD
- ID: 5901
-
- Once you've done "Bring Up To Date", you can "Build Code Resource".
- Then Quit from THINK-C and use ResEdit to Copy the XCMD resource
- from the XCmdDialog file and Paste it into a HyperCard stack.
- I've supplied a HyperCard 2.0 stack called XCmdStack that already
- has this XCMD in place (along with a couple of others). There is
- also a card-script (shown below) that gives Dialog a workout.
- Just bring up the Message Box (command-M), and type: tryit
-
- On tryit
- Dialog
- get the result
- if it is not empty then put it into the message box
- Dialog "Play it again Sam?", 100, 80, "Geneva"
- End tryit
-
- Notice that XCmdUtil makes it simpler to code the examples in Chapter 6
- because most of the commonly used routines are included in XCmdUtil.
- Something like NewMenuBar would #include "XCmdUtil.h" and only define
- the prototype for: pascal void main (XCmdBlockPtr); and you'd replace
- the CheckParamCount call as follows:
-
- if (CheckParamCount(paramPtr,requiredParamCount) < 0)
- { Fail(paramPtr, "Form: NewMenuBar \"Your About Name\"");
- return;
- }
-
- And you'd only have to code the main routine. If you make use of any of
- the string-functions, like "strcpy" in the NewMenuBar XCMD, then you must
- #include <string.h> to guarantee the proper prototypes are defined. That
- is true of any of the examples in Chapter 6. Not all string-functions
- have been defined in XCmdStrings, so take a look at XCmdStrings.c before
- using string-functions. If they aren't there, you may have to add them.
- And note that XCmdUtil.c needs XCmdStrings.c, so be sure to have both of
- them in your project window, or use the standard ANSII library in place
- of the XCmdStrings.c module. It's up to you.
-
- Lastly, pay particular attention to the Hints and Tips at the end of
- Chapter 2. The ID-numbers of Code Resources must not conflict, and you
- must "Name" them with names that don't conflict with HyperCard reserved
- words. Use "Set Project Type" to make changes for other XCMDs. You just
- replace the XCmdDialog.c module in the XCmdGlue.π project, and make a new
- XCMD file (Note that XCmdGlue.π.rsrc defines the XCMD icon).
-
- Have fun!
-